/**
 * 
 */
package view.impl.menu;

import org.newdawn.slick.Graphics;



/**
 * @author Julian
 *
 */
public class CascadedMenu {
	
	CascadedMenuLayer entry = null;
	
	public void setEntryLayer(CascadedMenuLayer layer) {
		entry = layer;	
	}
	
	public void draw(int[] selections, Graphics g, int windowWidth, int windowHeight) {
		float scaleX = (float)windowWidth / 800f;
		float scaleY = (float)windowHeight / 600f;
		
		CascadedMenuLayer[] layers =  new CascadedMenuLayer[selections.length];
		layers[0] = entry;
		for(int i = 0; i < layers.length - 1; i++) {
			layers[i+1] = layers[i].getTargetLayer(selections[i]);
		}
		
		int totalWidth = 0;
		for(CascadedMenuLayer layer : layers) {
			totalWidth += layer.getWidth();
		}
		
		// bug
		int spacePerSection = (int) ((float)totalWidth / (float)layers.length * (float)scaleX);
		int posX = spacePerSection;
		for(int i = 0; i < layers.length; i++) {
			CascadedMenuLayer layer = layers[i];
			int posY = (int) (400 + (200 * scaleY - layer.getHeight()) / 2);
			layer.setPos(posX, posY);
			
			layer.draw(selections[i], g, windowWidth, windowHeight);
			
			posX += layer.getWidth() + spacePerSection;
		}
	}
}
